#include "vector2.h"
#include <math.h>

CVector2::CVector2(void)
{
	x = 0;
	y = 0;
}

CVector2::CVector2(double l_iX, double l_iY)
{
	x = l_iX;
	y = l_iY;
}

CVector2::CVector2(const CVector2 & l_v2Parameter)
{
	this->x = l_v2Parameter.x;
	this->y = l_v2Parameter.y;
}

CVector2::~CVector2()
{
}

CVector2 & CVector2::operator=(const CVector2 & l_v2Parameter)
{
	if (this == &l_v2Parameter) return * this;

	this->x = l_v2Parameter.x;
	this->y = l_v2Parameter.y;
	
	return *this;

}

bool CVector2::operator==(const CVector2 &l_v2Parameter) const
{
	if((x == l_v2Parameter.x)&&(y == l_v2Parameter.y))
	{
		return true;
	}
	else
	{
		return false;
	}
}

CVector2 CVector2::operator+(const CVector2 & l_v2Parameter) const
{
	CVector2 l_v2Vector;

	l_v2Vector.x = x + l_v2Parameter.x;
	l_v2Vector.y = y + l_v2Parameter.y;

	return l_v2Vector;
}

CVector2 CVector2::operator*(const double l_iParameter) const
{
	CVector2 l_v2Vector;

	l_v2Vector.x = x * l_iParameter;
	l_v2Vector.y = y * l_iParameter;

	return l_v2Vector;
}

double CVector2::operator*(const CVector2 &l_v2Parameter) const
{
	double l_iResult;

	l_iResult = x * l_v2Parameter.x + y * l_v2Parameter.y;

	return l_iResult;
}

void CVector2::Normalize()
{
	double l_dLength = Length();

	x /= l_dLength;
	y /= l_dLength;

}
double CVector2::Length()
{
	return sqrt(x * x + y * y);
}

CVector2 operator*(const double l_iParameter, const CVector2 & l_v2Parameter)
{
	CVector2 l_v2Result;

	l_v2Result.x = l_iParameter * l_v2Parameter.x;
	l_v2Result.y = l_iParameter * l_v2Parameter.y;

	return l_v2Result;
}

